﻿using System.Xml;
using System.Xml.Serialization;

namespace SMARTMobile.WinPhone
{
    [XmlRoot("Configuration")]
    public class PhoneConfiguration
    {
        private static object SyncRoot = new object();
        private static PhoneConfiguration _current;
        
        public static PhoneConfiguration Current
        {
            get
            {
                if (null == _current)
                {
                    lock (SyncRoot)
                    {
                        if (null == _current)
                        {
                            using (var reader = XmlReader.Create("Configuration.xml"))
                            {
                                var s = new XmlSerializer(typeof(PhoneConfiguration));
                                _current = s.Deserialize(reader) as PhoneConfiguration;
                                _current.Prepare();
                            }
                        }
                    }
                }

                return _current;
            }
        }

        public DataSourcesConfiguration DataSourceMap { get; set; }

        public PageNavigationConfiguration NavigationMap { get; set; }

        public PushNotificationConfiguration PushNotification { get; set; }

        public void Prepare()
        {
            if (null != DataSourceMap)
                DataSourceMap.Prepare();

            if (null != NavigationMap)
                NavigationMap.Prepare();
        }
    }
}
